package com.hwg.shiliupro.service.Impl;

import com.hwg.shiliupro.dao.SessionListMapper;
import com.hwg.shiliupro.po.SessionList;
import com.hwg.shiliupro.service.SessionListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SessionListServiceImpl implements SessionListService {
    @Autowired
    private SessionListMapper sessionListMapper;
    @Override
    public SessionList selectById(Integer id) {
        return sessionListMapper.selectById(id);
    }

    @Override
    public int addUnReadCount(Integer userId, Integer toUserId) {
        return sessionListMapper.addUnReadCount(userId,toUserId);
    }

    @Override
    public Integer selectByUserIdAndToUserId(Integer userId, Integer toUserId) {
        return sessionListMapper.selectByUserIdAndToUserId(userId,toUserId);
    }

    @Override
    public int insert(SessionList newList) {
        return sessionListMapper.insert(newList);
    }

    @Override
    public List<SessionList> selectByUserId(Integer id) {
        return sessionListMapper.selectByUserId(id);
    }

    @Override
    public int delUnReadCount(Integer fromUserId, Integer toUserId) {
        int count = sessionListMapper.delUnReadCount(fromUserId, toUserId);
        return count;
    }


    /**
     * 通过当前登录的用户id 查询 toUserId(可建立会话用户)
     *
     * @param userId 用户id
     * @return {@link List}<{@link Integer}>
     */
    @Override
    public List<Integer> selectToUserIdByFromUserId(Integer userId) {
        return sessionListMapper.selectToUserIdByFromUserId(userId);
    }

    @Override
    public int deleteById(Integer sessionId) {
        return sessionListMapper.deleteById(sessionId);
    }
}
